<?php
require_once './config.php';

$key = $_REQUEST['key'];
$page = $_REQUEST['page'];
$size = $_REQUEST['size'];
$type = $_REQUEST['type']; // 排序方式  desc  asc
$sort = $_REQUEST['sort']; // 排序字段

$skip = ($page - 1) * $size;

$sql = "SELECT * from goodsinfo WHERE gname LIKE '%$key%' ORDER BY $sort $type LIMIT $skip,$size";

$result = mysqli_query($conn, $sql);

$obj = array(
    'code' => 1,
    'msg' => 'success',
);

$list = array();

while ($data = mysqli_fetch_assoc($result)) {
    $list[] = $data;
}

$obj['data'] = $list;

$sql = "SELECT count(*) from goodsinfo WHERE gname LIKE '%$key%'";

$result = mysqli_query($conn, $sql);

$data = mysqli_fetch_assoc($result);

$obj['count'] = $data['count(*)'];

echo json_encode($obj);

